class Courseetails{
    constructor(tag) {
        this.obTag = document.querySelector(tag)
        this.data_list = []
        this.initial()
    }
    async initial() {
        // 获取课程信息
        await this.courseInfo()
        // // 获取课程介绍内容
        await this.goodsExplain()
        // // 绑定事件
        // await this.bindEvent()
    }
    async courseInfo(){
        console.log(window.location.href)
        console.log(window.location.href.split("&")[2].split("=")[1])
        var get_productid=window.location.href.split("&")[2].split("=")[1]
        var res_pro=await fetch(`https://apis.wanxue.cn/gaoshou/v2/products/${get_productid}/goodses`,{
            headers: {
                a: 12,
                forwardId: 70,
                h: "wanxue",
                p: 1,
                u: "ffffffff-8d13-a56b-7169-0c980033c587",
                v: 5020501
            }
        })
        console.log(res_pro)
        var res=await res_pro.json()
        console.log(res)
        this.renderPage(res.result)
    }
    async goodsExplain(){
        // var get_productid=window.location.href.split("&")[2].split("=")[1]
        var get_productid=new URL(location.href).searchParams.get("productId")
        console.log(get_productid)
        var res_pro=await fetch(`https://apis.wanxue.cn/gaoshou/v1/goods/${get_productid}/explain`,{
            headers: {
                a: 12,
                forwardId: 70,
                h: "wanxue",
                p: 1,
                u: "ffffffff-8d13-a56b-7169-0c980033c587",
                v: 5020501
            }
        })
        var res=await res_pro.json()
        console.log(res.result.contentUrl)
        var content=document.querySelector(".info")
        content.innerHTML=res.result.content
    }
    async renderPage(data){
        console.log(data.subjectName)
        var tag_name=document.querySelector(".tag_content")
        console.log(tag_name)
        tag_name.innerHTML=data.subjectName
        var course_name=document.querySelector(".name")
        console.log(course_name)
        course_name.innerHTML=data.name
        var validTime=document.querySelector(".validTime")
        validTime.innerHTML="课程有效期："+data.extra.validTime
        var courseHour=document.querySelector(".courseHour")
        courseHour.innerHTML=data.courseHour+"课时"
        var price=document.querySelector(".price_free")
        if(data.price===0.00){
            price.innerHTML="免费"
        }else{
            price.innerHTML=data.price
        }
    }
}
new Courseetails("div")
console.log(window.location.href)